/*******************************************************************************
 * Copyright (c) 2007 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/
package org.eclipse.pde.internal.core.product;

import java.io.PrintWriter;
import org.eclipse.pde.internal.core.iproduct.IProductCustomizationConstants;
import org.eclipse.pde.internal.core.iproduct.IProductModel;
import org.w3c.dom.Node;

/**
 *
 */
public class RemoveTransform extends ProductTransform {

	private static final long serialVersionUID = 4995013193467419308L;

	public static final String TRANSFORM_ID = "remove"; //$NON-NLS-1$

	/**
	 * @param selected
	 */
	public RemoveTransform(IProductModel model, Object transformedObject) {
		super(model);
		setTransformedObject(transformedObject);
	}

	/**
	 * @param model
	 */
	public RemoveTransform(IProductModel model) {
		super(model);
	}

	/* (non-Javadoc)
	 * @see org.eclipse.pde.core.IWritable#write(java.lang.String,java.io.PrintWriter)
	 */
	public void write(String indent, PrintWriter writer) {
		if (fXPath != null) {
			StringBuffer sb = new StringBuffer();
			sb.append(indent).append("<"); //$NON-NLS-1$
			sb.append(TRANSFORM_ID).append(" ").append(TARGET_ATT); //$NON-NLS-1$
			sb.append("=\"").append(fXPath).append("\" />"); //$NON-NLS-1$//$NON-NLS-2$
			writer.println(sb.toString());
		} // else TODO add error login
	}

	/* (non-Javadoc)
	 * @see org.eclipse.pde.internal.core.iproduct.IProductTransform#writeTransformEntry(java.lang.String, java.io.PrintWriter, java.lang.String)
	 */
	public void writeTransformEntry(String indent, PrintWriter writer, String type) {
		int idx = fXPath.indexOf('/', 1);
		if (fXPath != null && idx != -1) {
			if (IProductCustomizationConstants.TYPE_XSLT.equals(type)) {
				writer.print(indent);
				writer.print("<xsl:template match=\"");
				writer.print("/plugin");
				writer.print(fXPath.substring(idx));
				writer.println("\" />");
			}
		} // else TODO add error login

	}

	/* (non-Javadoc)
	 * @see java.lang.Object#equals(java.lang.Object)
	 */
	public boolean equals(Object obj) {
		if (obj instanceof RemoveTransform) {
			RemoveTransform other = (RemoveTransform) obj;
			if (other.fXPath.equals(fXPath))
				return true;
		}
		return false;
	}

	protected void parseData(Node node) {
	}

}
